if (!isObject(PacmanCollisionBehavior)) {
   %template = new BehaviorTemplate(PacmanCollisionBehavior);
   
   %template.friendlyName = "Pacman Collision Behavior";
   %template.behaviorType = "Recibe Colision";
   %template.description  = "Colision entre un fantasma y pacman";
}

function PacmanCollisionBehavior::takeDamage(%this, %assailant) {
    %this.kill();
}

function PacmanCollisionBehavior::kill(%this) {
   %this.owner.lives--;
   
   lives.text = %this.owner.lives;
   
   if (%this.owner.lives == 0) {
      %this.owner.safeDelete();
      return;
   }
   
   %this.owner.visible = false;
   %this.owner.collisionActiveReceive = false;
   %this.owner.schedule(5000, "revive");
}

function PacmanCollisionBehavior::revive(%this) {
	%this.owner.visible = true;
	%this.owner.collisionActiveReceive = true;
}

function PacmanCollisionBehavior::collide(%this, %collided) {
	%element = %collided.getBehavior("GhostCollisionBehavior");
	
	if (isObject(%element)) {
		%this.kill();
		return;
	} else {
		%element = %collided.getBehavior("DotCollisionBehavior");
		if (isObject(%element)) {
			%element.eat(%this);
			%this.owner.score++;
			//score.text = %this.owner.score;
			%this.owner.updateScore();
		}
		
		return;
	}
}

function PacmanCollisionBehavior::onCollision(%this, %dstObj, %srcRef, %dstRef, %time, %normal, %contactCount, %contacts) {
   %this.collide(%dstObj);
}